package com.glodon.paas.document.web.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.glodon.paas.document.service.util.WebService;

@Controller
public class DatabagController {

    @Autowired
    private WebService webService;
    
    @RequestMapping(value = "/bag/{databagId}/progress", method = RequestMethod.GET)
    @ResponseBody
    public String queryProgress(@PathVariable("databagId")
    String databagId, HttpServletResponse resp) {
        String progress = webService.queryDatabagProgress(databagId);
        if ("100".equals(progress)) { // 100代表数据包完成，可以再浏览器端缓存结果
            resp.addHeader("Cache-Control", "max-age=315360000000");
        }
        return progress;
    }
}
